;////////////////////////////////////////////////////////////////
; 暗黑3窗口标题
d3_win_title = ahk_class D3 Main Window Class
;d3_win_title = ahk_class Chrome_WidgetWin_1
;////////////////////////////////////////////////////////////////
; 鼠标左键原地攻击标志
stand_attack_flag = 1
stand_attack_key = w
;////////////////////////////////////////////////////////////////
main_tick_interval = 20
main_tick_count = 0
;////////////////////////////////////////////////////////////////
hold_flag = 0
hold_flag_1 = 0
hold_flag_2 = 0
hold_flag_3 = 0
hold_flag_4 = 0
;////////////////////////////////////////////////////////////////
#SingleInstance
CoordMode, ToolTip | Mouse1
SetKeyDelay, 0, 20
;Hotkey, ~w, StandAttack, on
SetTimer, main_tick, %main_tick_interval%
return
;////////////////////////////////////////////////////////////////
ShowToolTip(msg, interval = 750)
{
	ToolTip, %msg%
	SetTimer, RemoveToolTip, %interval%
}

RemoveToolTip:
	SetTimer, RemoveToolTip, off
	ToolTip
return
;////////////////////////////////////////////////////////////////
; 退出本工具
~F3::
	if hold_flag = 0
	{
		hold_flag = 1
		ShowToolTip("Enable hold")
	}
	else
	{
		hold_flag = 0
		ShowToolTip("Disable hold")
	}
return
;////////////////////////////////////////////////////////////////
; 退出本工具
~F4::
	ExitApp
return
;///////////////////////////////////////////////////////////////
;显示鼠标当前坐标
!m::
	IfWinActive, %d3_win_title%
	{
		mouse_x = 0
		mouse_y = 0
		MouseGetPos, mouse_x, mouse_y
		msg = x = %mouse_x%, y = %mouse_y%
		ShowToolTip(msg)
	}
return
;///////////////////////////////////////////////////////////////
;鼠标左键原地攻击
StandAttack:
	IfWinActive, %d3_win_title%
	{
		if stand_attack_flag = 1
		{
			MouseGetPos, mouse_x, mouse_y
			ControlSend, , {Shift Down}, %d3_win_title%
			ControlClick, X%mouse_x% Y%mouse_y%, %d3_win_title%
			ControlSend, , {Shift Up}, %d3_win_title%
		}
	}
return
;///////////////////////////////////////////////////////////////
;鼠标左键原地攻击开关
!w::
	IfWinActive, %d3_win_title%
	{
		if stand_attack_flag = 0
		{
			stand_attack_flag = 1
			;Hotkey, ~w, StandAttack, on
			ShowToolTip("Enable stand attack")
		}
		else
		{
			stand_attack_flag = 0
			;Hotkey, ~w, StandAttack, off
			ShowToolTip("Disable stand attack")
		}
	}
return
;///////////////////////////////////////////////////////////////
main_tick:
    IfWinActive, %d3_win_title%
	{
        main_tick_count++

		if hold_flag = 1
		{
			if hold_flag_1 = 1
			{
				ControlSend, , {1}, %d3_win_title%
			}
			if hold_flag_2 = 1
			{
				ControlSend, , {2}, %d3_win_title%
			}
			if hold_flag_3 = 1
			{
				ControlSend, , {3}, %d3_win_title%
			}
			if hold_flag_4 = 1
			{
				ControlSend, , {4}, %d3_win_title%
			}
		}

		if stand_attack_flag = 1
		{
			if GetKeyState(stand_attack_key, P)
			{
				MouseGetPos, mouse_x, mouse_y
				ControlSend, , {Shift Down}, %d3_win_title%
				ControlClick, X%mouse_x% Y%mouse_y%, %d3_win_title%
				ControlSend, , {Shift Up}, %d3_win_title%
			}
		}
    }
return
;///////////////////////////////////////////////////////////////
!a::
	IfWinActive, %d3_win_title%
	{
		if hold_flag_1 = 0
		{
            ShowToolTip("Hold 1")
			hold_flag_1 = 1
		}
		else
		{
            ShowToolTip("Unhold 1")
			hold_flag_1 = 0
		}
	}
return

!s::
	IfWinActive, %d3_win_title%
	{
		if hold_flag_2 = 0
		{
            ShowToolTip("Hold 2")
			hold_flag_2 = 1
		}
		else
		{
            ShowToolTip("Unhold 2")
			hold_flag_2 = 0
		}
	}
return

!d::
	IfWinActive, %d3_win_title%
	{
		if hold_flag_3 = 0
		{
            ShowToolTip("Hold 3")
			hold_flag_3 = 1
		}
		else
		{
            ShowToolTip("Unhold 3")
			hold_flag_3 = 0
		}
	}
return

!f::
	IfWinActive, %d3_win_title%
	{
		if hold_flag_4 = 0
		{
            ShowToolTip("Hold 4")
			hold_flag_4 = 1
		}
		else
		{
            ShowToolTip("Unhold 4")
			hold_flag_4 = 0
		}
	}
return
